package com.iter.devbox.pattern.chain;

import java.util.LinkedList;
import java.util.List;

/**处理器链*/
public class FilterChain {
	/**请求对象*/
	private Request request;
	/**返回对象*/
	private Response response;
	/**处理器集合*/
	private List<Filter> filterList = new LinkedList<Filter>();

	public FilterChain(Request request, Response response) {
		this.request = request;
		this.response = response;
	}

	public Request getRequest() {
		return request;
	}

	public void setRequest(Request request) {
		this.request = request;
	}

	public Response getResponse() {
		return response;
	}

	public void setResponse(Response response) {
		this.response = response;
	}

	public void addFilter(Filter filter) {
		filterList.add(filter);
	}

	public void doFilter(Request request, Response response) {
		/**循环调用每一个具体的处理器*/
		for (Filter filter : filterList) {
			filter.doFilter(request, response);
		}
	}
}
